package com.xxx.service.impl;

import com.xxx.pojo.Admin;
import com.xxx.pojo.Menu;
import com.xxx.mapper.MenuMapper;
import com.xxx.service.IMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author WXH
 * @since 2022-02-23
 */
@Service
@Slf4j
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {

    @Autowired
    private MenuMapper menuMapper;

    /**
     * 通过用户id查询菜单列表
     *
     * @return List
     */
    @Override
    public List<Menu> getMenusByAdminId() {
        Admin admin = (Admin) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        int id = admin.getId();
        log.info("用户id：" + id);
        List<Menu> menusByAdminId = menuMapper.getMenusByAdminId(id);
        for (Menu menu : menusByAdminId) {
            System.out.println(menu);
        }
        return menuMapper.getMenusByAdminId(id);
    }

    /**
     * 根据角色获取菜单列表
     *
     * @return List
     */
    @Override
    public List<Menu> getMenuWithRole() {
        return menuMapper.getMenuWithRole();
    }

    @Override
    public List<Menu> getAllMenus() {

        return menuMapper.getAllMenus();
    }
}
